//
//  ViewController.swift
//  SwiftTest
//
//  Created by Mjwon on 2016/12/7.
//  Copyright © 2016年 Nemo. All rights reserved.
//

import UIKit

class ViewController: UIViewController ,UITableViewDelegate,UITableViewDataSource{

    open var speed: Double = 0.0 {
        
        didSet {
            print(self.speed);
        }
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        
        
        self.view.backgroundColor = UIColor.white;
        
        
        let tableView = UITableView.init(frame: CGRect(x:0,y:0,width:375,height:667));
        
        tableView.delegate = self;
        
        tableView.dataSource = self;
        
        self.view.addSubview(tableView);
        
        test();
    }
    
    func numberOfSections(in tableView: UITableView) -> Int {
        return 1;
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 10;
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        var cell = tableView.dequeueReusableCell(withIdentifier: "demoCell");
        
        if cell == nil {
            cell = UITableViewCell.init(style: .default, reuseIdentifier: "demoCell");
        }
        
        cell?.textLabel?.text = String.init(format:"%ld", indexPath.row);
        
        return cell!;
    }
    
    func test() -> Void {
        let dataSource = NSMutableArray.init();
        
        for _ in 1...10{
            
            let image = UIImageView.init();
            dataSource.add(image);
            
        }
        
        let a = NSMutableArray.init(array: ["1","2","3","4","5","6","7"]);
        
        a.enumerateObjects({ (obj, idx, stop) in
            
            print("a:",obj)
            
            if(idx == 2){
                stop.initialize(to: ObjCBool(true))
            }
            
        })
        
        for (idx,itme) in a.enumerated() {
            
            print(idx,itme);
            if idx == 3 {
                a.replaceObject(at: idx, with: "10");
            }
        }
        
         print(a);
        
        self.speed = 1000;
        
        print(self.speed,"cccc");
        
        for image in dataSource {
            let imageV = image as! UIImageView;
            imageV.backgroundColor = UIColor.red;
        }

    }
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let vc = TestViewController.init();
        
//        vc.headerClick = {(str:String)->Void in
//            print(str)
//            self.title = str;
//        };
        
        self.navigationController?.pushViewController(vc, animated: true);
    }
    

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

